import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import org.bson.Document;

public class GetExcel {
    static MongoClientOptions.Builder builder = new MongoClientOptions.Builder();
    static MongoClientOptions options = builder.maxConnectionIdleTime( 100000 ).build();
    static MongoClient client1 = new MongoClient( "192.168.1.174:27017", options );
    public static void main(String[] args) {
        MongoCollection<Document> collection = client1.getDatabase("KAMD").getCollection("KAMD_Date_2020");
        FindIterable<Document> documents = collection.find().sort(new org.bson.Document("_id", 1));
        documents.noCursorTimeout(true);
        for (Document document : documents) {
            String scode = document.getString("Scode");
            String Name = document.getString("Name");
            String type_content = document.getString("type_content");
            String GetTitle=Get(type_content.replaceAll(" ",""));
            System.out.println(GetTitle);
        }
    }


    public static String Get(String content){
        int index=0;
        if(content.contains("我们将")){
            index=content.lastIndexOf("我们将");
        }else if(content.contains("我们确定")){
            index=content.lastIndexOf("我们确定");
        }

        int lastindex=content.lastIndexOf("识别为关键审计事项");
        int lastindex2=content.lastIndexOf(" 确认为关键审计事项");
        int lastindex3=content.lastIndexOf("作为关键审计事项");
        int lastindex4=content.lastIndexOf("确定为关键审计事项");
        int lastindex5=content.lastIndexOf("认定为关键审计事项");
        int lastindex6=content.lastIndexOf("列为关键审计事项");
        int lastindex7=content.lastIndexOf("为关键审计事项");
        int lastindex8=content.lastIndexOf("视为关键审计事项");
        int lastindex9=content.lastIndexOf("作为一项关键审计事项");
        int lastindex10=content.lastIndexOf("确认为关键审计事项");
        //int lastindex6=content.lastIndexOf("列为关键审计事项");
        if(index>0&&lastindex>index){
            content=content.substring(index,lastindex).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex2>index){
            content=content.substring(index,lastindex2).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex3>index){
            content=content.substring(index,lastindex3).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex4>index){
            content=content.substring(index,lastindex4).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex5>index){
            content=content.substring(index,lastindex5).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex6>index){
            content=content.substring(index,lastindex6).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex7>index){
            content=content.substring(index,lastindex7).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex8>index){
            content=content.substring(index,lastindex8).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex9>index){
            content=content.substring(index,lastindex9).replace("我们将","").replace("我们确定","");
        }else if(index>0&&lastindex10>index){
            content=content.substring(index,lastindex10).replace("我们将","").replace("我们确定","");
        }else {
            content="";
        }
        return content;
    }
}
